import scrapy

from ScrapyObject.spiders.utils.url_utils import *
'''
scrapy crawl tempaa -o tempaa.json
https://jiujiure00.com/
a、b、c、d、e、f、g、h、i、j、k、l、m、n、o、p、q、r、s、t、u、v、w、x、y、z

scrapy genspider tempad https://www.gcjpgm2.sbs/
'''

class TempaaSpider(scrapy.Spider):
    name = "tempaa"
    # 前缀
    prefix = 'https://'
    # 中缀
    website = 'jiujiure00'
    # 后缀
    suffix = '.com/'
    allowed_domains = [website + '.com']
    start_urls = [prefix + website + suffix]

    def __init__(self):
        self.i = 0

    def parse(self, response):
        content = get_data(response)
        video_url = get_video_url_one(content)
        tags = response.xpath("//div[@class='list-nav']//span//a/text()").extract()
        name = response.xpath("//div[@class='list-nav']//span/text()").extract()
        p_url = response.xpath("//div[@class='left']//img/@ src").extract()
        if len(video_url) and len(tags) and len(name) and len(p_url):
            self.i = self.i + 1
            yield get_video_item(id=self.i, tags=tags[-1], url="", name=name[-1].replace("»", "").strip(), pUrl=split_joint(self.prefix + self.website + self.suffix, p_url[0]), vUrl=video_url[0])
        url_list = get_url(content)
        for url in url_list:
            if url.startswith('/') and url.endswith('.html'):
                yield scrapy.Request(split_joint(self.prefix + self.website + self.suffix, url), callback=self.parse)